package com.jrtc.backend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jrtc.base.config.dto.ResultDTO;
import com.jrtc.base.config.dto.ResultDTOBuilder;
import com.jrtc.base.entity.bo.CatchBallRecord;
import com.jrtc.base.entity.bo.Department;
import com.jrtc.base.entity.vo.CatchBallRecordVo;
import com.jrtc.service.CatchBallRecordService;
import com.jrtc.service.DepartmentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("catchBallRecord")
public class CatchBallRecordController {
    /**
     * 服务对象
     */
    @Resource
    private CatchBallRecordService catchBallRecordService;

    /**
     * 添加患者抓小球记录
     * */
    @PostMapping("/insertRecord")
    public ResultDTO insertRecord(@RequestBody CatchBallRecord catchBallRecord){
        CatchBallRecordVo catchBallRecordVo;
        try {
            catchBallRecordVo = catchBallRecordService.insertRecord(catchBallRecord);
        } catch (Exception e){
            return ResultDTOBuilder.failure(e.getMessage());
        }

        return ResultDTOBuilder.success(catchBallRecordVo);
    }

    /**
     * 抓小球记录图表
     * */
    @PostMapping("/record")
    public ResultDTO record(@RequestBody Map<String, Object> map){
        Integer id = Integer.parseInt(map.get("id").toString());
        CatchBallRecord catchBallRecord = catchBallRecordService.record(id);
        return ResultDTOBuilder.success(catchBallRecord);
    }
}